/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

package com.tbit.uqbike.object.pojo.bo;

import cn.hutool.core.util.StrUtil;
import com.tbit.uqbike.object.pojo.vo.MannedBindingExcelVO;
import com.tbit.uqbike.object.value.LoginInfo;
import lombok.Data;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author <a href="mailto:li.yao@tbit.com.cn">yao</a>
 * @version 4.2.0
 * @since 2024/9/19 10:57
 */
@Data
public class MannedBatchBindBO {

    private Integer accountId;

    private LoginInfo loginInfo;

    private List<MannedBindingBO> mannedBindingList;

    public static MannedBatchBindBO of(Integer accountId, LoginInfo loginInfo, List<MannedBindingExcelVO> mannedExcelBindingList) {
        MannedBatchBindBO mannedBatchBindBO = new MannedBatchBindBO();
        mannedBatchBindBO.setAccountId(accountId);
        mannedBatchBindBO.setLoginInfo(loginInfo);
        List<MannedBindingBO> mannedBindingList = mannedExcelBindingList.stream().map(MannedBindingBO::new).collect(Collectors.toList());
        mannedBatchBindBO.setMannedBindingList(mannedBindingList);
        return mannedBatchBindBO;
    }

    public static MannedBatchBindBO of(Integer accountId, LoginInfo loginInfo, MannedBindingExcelVO mannedExcelBindingList) {
        return of(accountId, loginInfo, Collections.singletonList(mannedExcelBindingList));
    }

    public List<String> getUserCodes() {
        return mannedBindingList.stream()
                .map(MannedBindingBO::getMannedBinding)
                .map(MannedBindingExcelVO::getUserCode)
                .filter(StrUtil::isNotBlank)
                .collect(Collectors.toList());
    }

    public List<String> getMannedNos() {
        return mannedBindingList.stream()
                .map(MannedBindingBO::getMannedBinding)
                .map(MannedBindingExcelVO::getMannedNo)
                .filter(StrUtil::isNotBlank)
                .collect(Collectors.toList());
    }

}
